package br.edu.ufcg.greengrid.workload;

import java.io.Serializable;
import java.util.Comparator;

import com.mallardsoft.tuple.Triple;
import com.mallardsoft.tuple.Tuple;

public class MachineAvailabilityComparator implements Comparator<Triple<String, Long, Long>>, Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public int compare(Triple<String, Long, Long> triple1, Triple<String, Long, Long> triple2) {
		int compare;

		Long timestamp1 = Tuple.get2(triple1);
		Long timestamp2 = Tuple.get2(triple2);

		compare = timestamp1.compareTo(timestamp2);
		if (compare != 0) {
			return compare;
		}

		Long idletime1 = Tuple.get3(triple1);
		Long idletime2 = Tuple.get3(triple2);

		compare = idletime1.compareTo(idletime2);
		if (compare != 0) {
			return compare;
		}

		String machine1 = Tuple.get1(triple1);
		String machine2 = Tuple.get1(triple2);

		compare = machine1.compareTo(machine2);
		if (compare != 0) {
			return compare;
		}

		return 0;
	}

}
